<template>
  <!--日志管理-->
  <div id="base">
    <!-- 搜索 -->
    <div class="search">
      <div class="searchTop">
        <el-form :inline="true" :model="search">
          <el-form-item label="告警站点">
            <el-select v-model="search.stationId" placeholder="请选择" clearable>
              <el-option
                v-for="item in siteList"
                :key="item.id"
                :label="item.stationName"
                :value="item.id"
              ></el-option>
            </el-select>
            <!-- <el-input v-model="search.warningStation" placeholder="请输入告警站点"></el-input> -->
          </el-form-item>
          <el-form-item label="告警类型">
            <el-select v-model="search.warningType" placeholder="请选择告警类型" clearable>
              <el-option label="电压告警" value="2"></el-option>
              <el-option label="水位告警" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="告警时间">
            <el-date-picker
              v-model="search.searchTime"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getAddBook">查询</el-button>
            <el-button @click="empty" type="info">清空</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>

    <!-- 列表 -->
    <div id="table">
      <el-table
        :data="dataa.list"
        border
        style="width: 100%"
        :header-cell-style="{ background: 'rgba(237, 242, 246, 1)' }"
      >
        <el-table-column prop="num" type="index" label="序号" width="50"></el-table-column>
        
        <el-table-column prop="createTime" label="告警时间" width="180"></el-table-column>
        <el-table-column prop="warningStation" label="告警站点" width="180"></el-table-column>
        <el-table-column label="告警类型" width="180">
          <template slot-scope="scope">
            <span
              :class="scope.row.warningType ==0?'green':'red'"
            >{{scope.row.warningType ==2?'电压告警':'水位告警'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="warningMsg" label="告警内容"></el-table-column>
      </el-table>
    </div>

    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="dataa.total"
        @current-change="currentpage"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      addedittitle: null,
      showedit: false,
      dialogFormVisible: false,
      // 搜索
      search: {
        status: "",
        name: "",
        list: [],
        stationId: "",
        page: 1,
        size: 10
      },
      siteList: [],
      // 列表数据
      dataa: {
        pagesize: "",
        // currpage: "",
        list: []
      }
    };
  },
  created() {
    this.getList();
    this.$http
      .post("deviceWater/findStation", {
        companyId: localStorage.getItem("companyId")
      })
      .then(res => {
        this.siteList = res.data;
      });
  },
  methods: {
    table_index(index) {
      // return (this.data.currpage - 1) * this.data.pagesize + (index + 1);
    },
    //获取列表数据
    getList() {
      console.log(localStorage.getItem("companyId"));

      this.$http
        .post("waterWarning/findList", {
          ...this.search,
          // companyId: "4"
          companyId: localStorage.getItem("companyId")
        })
        .then(res => {
          // console.log(res);
          this.dataa = res.data;
          // this.data.currpage = 1;
          // this.data.list = res.data;
        });
    },
    //查询
    getAddBook() {
      this.getList();
    },
    //清空
    empty() {
      (this.search = {}), this.getList();
    },
    // 翻页
    currentpage(val) {
      this.search.page = val;
      this.getList();
    },
    // 显示条数切换
    sizeChange(total) {
      this.data.pagesize = total;
    }
  }
};
</script>

<style lang="less" scoped>
.search {
  // overflow: hidden;
  display: flex;
  justify-content: space-between;
}
.table {
  width: 1128px;
  height: 465px;
  margin-top: 16px;
}
.table {
  width: 100%;
}
.textmsg {
  color: red;
}
.textcc {
  color: #000;
}
.paginationList {
  text-align: center;
  margin-top: 32px;
  padding: 0;
}
.table {
  width: 1128px;
  height: 465px;
  margin-top: 16px;
}
.pagination {
  text-align: center;
  margin-right: 25px;
  padding-top: 20px;
}
.green {
  // color: green;
  font-weight: 600;
}
.red {
  // color: red;
  font-weight: 600;
}
.texter {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
